﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PermissionReporting
{
    public partial class Login : Form
    {
        public SPCredentials CurrentUserCredentials { get; set; }
        public Login()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string username = textBox1.Text.Trim();
            string password = textBox2.Text.Trim();

            if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
            {
                CurrentUserCredentials = new SPCredentials()
                {
                    UserName = username,
                    Password = password
                };
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void Login_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode==Keys.Enter)
            {
                string username = textBox1.Text.Trim();
                string password = textBox2.Text.Trim();

                if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
                {
                    CurrentUserCredentials = new SPCredentials()
                    {
                        UserName = username,
                        Password = password
                    };
                }
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
    }
}
